package com.charles.video.system.service.impl;

import com.charles.video.common.core.responseDomain.TableInfo;
import com.charles.video.common.core.utils.PageUtils;
import com.charles.video.system.mapper.VideoCommentsMapper;
import com.charles.video.system.mapper.VideoCommentsReplyMapper;
import com.charles.video.system.service.CommentsService;
import com.charles.video.system.vo.CommentDataVo;
import com.charles.video.system.vo.SearchCommentForm;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Charles-H
 * 
 * 评论数据实现类
 */
@Service
public class CommentsServiceImpl implements CommentsService {
    
    @Resource
    private VideoCommentsMapper videoCommentsMapper;
    
    @Resource
    private VideoCommentsReplyMapper videoCommentsReplyMapper;
    
    @Override
    public TableInfo queryCommentsData(Integer pageNum, Integer pageSize, SearchCommentForm searchCommentForm) {
        List<CommentDataVo> commentDataVos = new ArrayList<>();
        commentDataVos.addAll(videoCommentsMapper.queryCommentData(searchCommentForm));
        commentDataVos.addAll(videoCommentsReplyMapper.queryCommentData(searchCommentForm));
        
        List<CommentDataVo> packageData = (List<CommentDataVo>) PageUtils.startPage(commentDataVos, pageNum, pageSize);
        TableInfo rspData = new TableInfo();
        rspData.setCode(200);
        rspData.setRows(packageData);
        rspData.setMsg("查询成功");
        rspData.setTotal(new PageInfo(commentDataVos).getTotal());
        return rspData;
    }
    
}
